<?php
/**
 * CreateTime: 2023/11/17 15:36
 * User:LinQ
 */

namespace App\Func\System;

class ConfigFunc
{
    /**
     * 获取系统默认生成公钥
     * @return false|string
     */
    public function getDefaultPuKey(): bool|string
    {
        $path = database_path('seeders').DIRECTORY_SEPARATOR.'System'.DIRECTORY_SEPARATOR."pu_key.pem";
        if(!is_file($path)){
            s_fail_return(null,trans('message.not_exists',[
                'name' => trans('key.pu_key')
            ]));
        }
        return file_get_contents($path);
    }

    /**
     * 获取系统默认生成的私钥
     * @return false|string
     */
    public function getDefaultPvKey(): bool|string
    {
        $path = database_path('seeders').DIRECTORY_SEPARATOR.'System'.DIRECTORY_SEPARATOR."pv_key.pem";
        if(!is_file($path)){
            s_fail_return(null,trans('message.not_exists',[
                'name' => trans('key.pv_key')
            ]));
        }
        return file_get_contents($path);
    }

    /**
     * 通过公钥获取默认的iv
     * @return string
     */
    public function getDefaultIv(): string
    {
        $puKey = $this->getDefaultPuKey();
        return get_iv($puKey);
    }
}